home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gsl.idb / usr / freeware / include / gsl_interp.h.z / gsl_interp.h
Encoding:
C/C++ Source or Header  |  1999-07-16  |  3.3 KB  |  123 lines

  1. /* Author:  G. Jungman
  2.  * RCS:     $Id: gsl_interp.h,v 1.7 1998/11/14 02:10:51 bjg Exp $
  3.  */
  4. #ifndef GSL_INTERP_H_
  5. #define GSL_INTERP_H_
  6.  
  7.  
  8. /* evaluation accelerator */
  9. typedef struct {
  10.   size_t  cache;        /* cache of index   */
  11.   size_t  miss_count;   /* keep statistics  */
  12.   size_t  hit_count;
  13. }
  14. gsl_interp_accel;
  15.  
  16.  
  17. /* general interpolation object */
  18. struct _gsl_interp_obj_struct {
  19.   int     (*eval_impl)   (const struct _gsl_interp_obj_struct *, const double xa[], const double ya[], double x, gsl_interp_accel *, double * y);
  20.   int     (*eval_d_impl) (const struct _gsl_interp_obj_struct *, const double xa[], const double ya[], double x, gsl_interp_accel *, double * dydx);
  21.   void    (*free)        (struct _gsl_interp_obj_struct *);
  22.   double  xmin;
  23.   double  xmax;
  24.   size_t     size;
  25. };
  26. typedef  struct _gsl_interp_obj_struct  gsl_interp_obj;
  27.  
  28.  
  29. /* interpolation object factory */
  30. typedef struct {
  31.   const char * name;
  32.   gsl_interp_obj *  (*create) (const double x_array[], const double y_array[], size_t size);
  33. }
  34. gsl_interp_factory;
  35.  
  36.  
  37. /* available factories */
  38. extern const gsl_interp_factory   gsl_interp_factory_linear;
  39. extern const gsl_interp_factory   gsl_interp_factory_cspline_natural;
  40. extern const gsl_interp_factory   gsl_interp_factory_cspline_periodic;
  41. extern const gsl_interp_factory   gsl_interp_factory_akima_natural;
  42. extern const gsl_interp_factory   gsl_interp_factory_akima_periodic;
  43.  
  44.  
  45. gsl_interp_accel *
  46. gsl_interp_accel_new(void);
  47.  
  48. size_t
  49. gsl_interp_accel_find(gsl_interp_accel * a, const double x_array[], size_t size, double x);
  50.  
  51. void
  52. gsl_interp_accel_free(gsl_interp_accel * a);
  53.  
  54.  
  55. int
  56. gsl_interp_eval_impl(const gsl_interp_obj * obj,
  57.                      const double xa[], const double ya[], double x,
  58.                      gsl_interp_accel * a, double * y
  59.                      );
  60.  
  61. int
  62. gsl_interp_eval_e(const gsl_interp_obj * obj,
  63.                   const double xa[], const double ya[], double x,
  64.                   gsl_interp_accel * a, double * y
  65.                   );
  66.  
  67. double
  68. gsl_interp_eval(const gsl_interp_obj * obj,
  69.                 const double xa[], const double ya[], double x,
  70.                 gsl_interp_accel * a
  71.                 );
  72.  
  73. int
  74. gsl_interp_eval_deriv_impl(const gsl_interp_obj * obj,
  75.                            const double xa[], const double ya[], double x,
  76.                gsl_interp_accel * a,
  77.                            double * y
  78.                            );
  79.  
  80. int
  81. gsl_interp_eval_deriv_e(const gsl_interp_obj * obj,
  82.                         const double xa[], const double ya[], double x,
  83.             gsl_interp_accel * a,
  84.                         double * y
  85.                         );
  86.  
  87. double
  88. gsl_interp_eval_deriv(const gsl_interp_obj * obj,
  89.                       const double xa[], const double ya[], double x,
  90.               gsl_interp_accel * a
  91.                       );
  92.  
  93. void
  94. gsl_interp_obj_free(gsl_interp_obj * interp_obj);
  95.  
  96.  
  97. #ifdef HAVE_INLINE
  98. #include "bsearch.h"
  99. inline
  100. size_t
  101. gsl_interp_accel_find(gsl_interp_accel * a, const double xa[], size_t len, double x)
  102. {
  103.   size_t x_index = a->cache;
  104.  
  105.   if(x < xa[x_index]) {
  106.     a->miss_count++;
  107.     a->cache = interp_bsearch(xa, x, 0, x_index);
  108.   }
  109.   else if(x > xa[x_index + 1]) {
  110.     a->miss_count++;
  111.     a->cache = interp_bsearch(xa, x, x_index, len-1);
  112.   }
  113.   else {
  114.     a->hit_count++;
  115.   }
  116.   
  117.   return a->cache;
  118. }
  119. #endif /* HAVE_INLINE */
  120.  
  121.  
  122. #endif  /* !GSL_INTERP_H_ */
  123.